package my_sort;

import java.util.Arrays;

/**
 * @author : niu niu
 * @version : 1.0.0
 * @date : 2023/3/27 14:24
 */
public class InsertSort {
    public static void main(String[] args) {
        int[] arr = {10,6,9,3,8,2,3};

        insertSort(arr);
        System.out.println(Arrays.toString(arr));
    }
    // 插入排序
    public static void insertSort(int[] array){
        // write code  here
        for (int i = 0; i < array.length-1; i++) {
            int x = array[i+1];
            int j;
            for ( j = i; j >=0 && array[j]>x ; j--) {
                array[j+1] = array[j];
            }
            array[j+1] = x;
        }
    }
}
